package com.armed.ejb.sessions;

import com.armed.ejb.entities.Comparativas;
import com.armed.ejb.transference.Comparativa;
import com.armed.ejb.transference.helpers.DataReverseTransferHelper;
import com.armed.ejb.transference.helpers.DataTransferHelper;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Class ComparativasFacade
 *
 *
 * @author init() software
 * @version 24/02/2008 
 */
@Stateless
public class ComparativasFacade implements ComparativasFacadeRemote 
{
    @PersistenceContext
    private EntityManager em;
    /** Constructor of ComparativasFacade */
    public ComparativasFacade()
    {
    }

    public void create(Comparativa comparativa)
    {
        Comparativas comp = DataReverseTransferHelper.revertComparative(comparativa);
        em.persist(comp);
    }

    public void edit(Comparativa comparativas)
    {
        em.merge(DataReverseTransferHelper.revertComparative(comparativas));
    }

    public void remove(Comparativa comparativa)
    {
        em.remove(em.merge(DataReverseTransferHelper.revertComparative(comparativa)));
    }

    public Comparativa find(Object id)
    {
        Comparativa c = null;
        c = DataTransferHelper.copyComparative(em.find(com.armed.ejb.entities.Comparativas.class,id));
        return c;
    }

    public List<Comparativa> findAll()
    {
        return DataTransferHelper.copyComparativesToList(em.createQuery("select object(o) from Comparativas as o").getResultList());
    }
}
